package sourceapi.client.mainpage;


import sourceapi.client.MenuItem;
import sourceapi.client.MenuManager;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.http.client.Request;
import com.google.gwt.user.client.History;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.HorizontalPanel;

public abstract class Base {
	
	protected static Request PageRequest;
	
	protected static void CancelRequest(){
		if( PageRequest != null ){
			PageRequest.cancel();
			PageRequest = null;
		}		
	}

	public static HorizontalPanel GetHeader( int id ){
		
		for( MenuItem Item : MenuManager.MenuList )
			if( Item.Id == id  )
				return GetHeader( Item.Name );
		
		return null;
	}
	
	public static HorizontalPanel GetHeader( final String name ){
		
		HorizontalPanel Spacer = new HorizontalPanel();
		
		Button Constants = new Button ( "Constants" , new ClickHandler() {
			public void onClick(ClickEvent event) {
				History.newItem( "c:" + name );
			}
		});
		Spacer.add(Constants);
		
		Button Functions = new Button ( "Functions" , new ClickHandler() {
			public void onClick(ClickEvent event) {
				History.newItem( "l:" + name );
			}
		});
		Spacer.add(Functions);
		
		Button File = new Button ( "File", new ClickHandler() {
			public void onClick(ClickEvent event) {
				History.newItem( "s:" + name );
			}
		});
		Spacer.add(File);
		
		
		return Spacer;
		
	}

}